<template>
    <el-card shadow="always" :body-style="{ padding: '20px' }">
        <div slot="header">
            <!-- 路径导航 -->
            <el-breadcrumb separator="/">
                <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>订单管理</el-breadcrumb-item>
                <el-breadcrumb-item>订单列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <!-- 搜素区域 -->
        <div>
            <el-form :model="form" ref="form" label-width="80px" :inline="true" size="normal">
                <el-form-item label="用户ID">
                    <el-input v-model="form.user_id" clearable></el-input>
                </el-form-item>
                <el-form-item label="支付状态">
                    <el-select v-model="form.pay_status">
                        <el-option label="全部" value></el-option>
                        <el-option label="已付款" value="1"></el-option>
                        <el-option label="未付款" value="0"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="发货状态">
                    <el-select v-model="form.is_send">
                        <el-option label="全部" value></el-option>
                        <el-option label="已发货" value="1"></el-option>
                        <el-option label="未发货" value="0"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="getOrderList">查询</el-button>
                    <el-button @click="reset">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <!-- 表格区域 -->
        <el-table :data="orderList" border>
            <el-table-column type="index" label="序号"></el-table-column>
            <el-table-column prop="order_id" label="订单编号"></el-table-column>
            <el-table-column prop="order_price" label="订单价格"></el-table-column>
            <el-table-column prop="user_id" label="用户ID"></el-table-column>
            <el-table-column prop="pay_status" label="支付状态">
                <template slot-scope="scope">
                    <el-button
                        type="success"
                        size="small"
                        v-if="scope.row.pay_status ==1"
                        circle
                        plain
                        icon="el-icon-check"
                    ></el-button>
                    <el-button
                        type="info"
                        size="small"
                        v-if="scope.row.pay_status ==0"
                        circle
                        plain
                        icon="el-icon-close"
                    ></el-button>
                </template>
            </el-table-column>
            <el-table-column prop="is_send" label="是否发货">
                <template slot-scope="scope">
                    <el-button
                        type="success"
                        size="small"
                        v-if="scope.row.is_send =='是'"
                        circle
                        plain
                        icon="el-icon-check"
                    ></el-button>
                    <el-button
                        type="primary"
                        size="small"
                        v-if="scope.row.is_send =='否'"
                        circle
                        plain
                        icon="el-icon-close"
                    ></el-button>
                </template>
            </el-table-column>
            <el-table-column label="下单时间">
                <template slot-scope="scope">{{scope.row.create_time | dataFormate}}</template>
            </el-table-column>
            <el-table-column prop="trade_no" label="是否热销">
                <template slot-scope="scope">
                    <el-button type="danger" size="small" v-if="!scope.row.trade_no" circle>是</el-button>
                    <el-button type="primary" size="small" v-else circle>否</el-button>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button
                        type="success"
                        size="small"
                        icon="el-icon-s-tools"
                        @click="editOrder(scope.row)"
                    ></el-button>
                    <el-button
                        type="danger"
                        size="small"
                        icon="el-icon-truck"
                        @click="seeExpress(scope.row)"
                    ></el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页器 -->
        <el-pagination
            background
            layout="prev,pager,next,jumper,->,total"
            :page-size="form.pagesize"
            :current-page="form.pagenum"
            :total="total"
            @current-change="pageChange"
        ></el-pagination>

        <!-- 查看物流弹框 -->
        <el-dialog title="物流信息" :visible.sync="dialogShow" width="60%">
            <el-row :gutter="20">
                <el-col :span="20" :offset="3">
                    <el-timeline :reverse="false">
                        <el-timeline-item
                            v-for="(item, index) in expressInfo"
                            :key="index"
                            :icon="item.icon"
                            :color="item.color"
                            :size="item.size"
                            :timestamp="item.time"
                        >{{item.context}}</el-timeline-item>
                    </el-timeline>
                </el-col>
            </el-row>

            <span slot="footer">
                <el-button @click="dialogShow = false">关闭</el-button>
            </span>
        </el-dialog>

        <!-- 修改订单弹框 -->
        <el-dialog title="修改收货地址" :visible.sync="editdialogShow" width="30%">
            <el-form
                v-model="addressForm"
                ref="addressForm"
                :rules="addressFormRule"
                label-width="120px"
            >
                <el-form-item label="省市县" prop="addressList">
                    <el-cascader :options="cityList" v-model="addressForm.addressList"></el-cascader>
                </el-form-item>
                <el-form-item label="具体详细地址" prop="detail_info">
                    <el-input v-model="addressForm.detail_info"></el-input>
                </el-form-item>
            </el-form>

            <span slot="footer">
                <el-button @click="editdialogShow = false">Cancel</el-button>
                <el-button type="primary" @click="editSubmit">OK</el-button>
            </span>
        </el-dialog>
    </el-card>
</template>
<script>
import city from "../../util/citydata";
let defaultOrder = {
    query: "",
    pagenum: 1,
    pagesize: 10,
    user_id: "",
    pay_status: "",
    is_send: "",
};
export default {
    data() {
        return {
            dialogShow: false,
            orderList: [],
            form: {
                ...defaultOrder,
            },
            total: 0,
            expressInfo: [],
            editdialogShow: false,
            addressForm: {
                addressList: [],
                detail_info: "",
            },
            addressFormRule: {
                addressList: [
                    {
                        required: true,
                        message: "请输入省市",
                        trigger: "blur",
                    },
                ],
                detail_info: [
                    {
                        required: true,
                        message: "请输入具体地址",
                        trigger: "blur",
                    },
                ],
            },
            cityList: city,
        };
    },
    methods: {
        // 查看物流
        seeExpress(row) {
            if (row.is_send === "是") {
                this.dialogShow = true;
                this.expressInfo = [
                    {
                        time: "2018-05-10 09:39:00",
                        ftime: "2018-05-10 09:39:00",
                        context: "已签收,感谢使用顺丰,期待再次为您服务",
                        location: "",
                        color: "#0bbd87",
                        size: "large",
                        icon: "el-icon-location-information",
                    },
                    {
                        time: "2018-05-10 08:23:00",
                        ftime: "2018-05-10 08:23:00",
                        context:
                            "[北京市]北京海淀育新小区营业点派件员 顺丰速运 95338正在为您派件",
                        location: "",
                    },
                    {
                        time: "2018-05-10 07:32:00",
                        ftime: "2018-05-10 07:32:00",
                        context: "快件到达 [北京海淀育新小区营业点]",
                        location: "",
                    },
                    {
                        time: "2018-05-10 02:03:00",
                        ftime: "2018-05-10 02:03:00",
                        context:
                            "快件在[北京顺义集散中心]已装车,准备发往 [北京海淀育新小区营业点]",
                        location: "",
                    },
                    {
                        time: "2018-05-09 23:05:00",
                        ftime: "2018-05-09 23:05:00",
                        context: "快件到达 [北京顺义集散中心]",
                        location: "",
                    },
                    {
                        time: "2018-05-09 21:21:00",
                        ftime: "2018-05-09 21:21:00",
                        context:
                            "快件在[北京宝胜营业点]已装车,准备发往 [北京顺义集散中心]",
                        location: "",
                    },
                    {
                        time: "2018-05-09 13:07:00",
                        ftime: "2018-05-09 13:07:00",
                        context: "顺丰速运 已收取快件",
                        location: "",
                    },
                    {
                        time: "2018-05-09 12:25:03",
                        ftime: "2018-05-09 12:25:03",
                        context: "卖家发货",
                        location: "",
                    },
                    {
                        time: "2018-05-09 12:22:24",
                        ftime: "2018-05-09 12:22:24",
                        context:
                            "您的订单将由HLA（北京海淀区清河中街店）门店安排发货。",
                        location: "",
                    },
                    {
                        time: "2018-05-08 21:36:04",
                        ftime: "2018-05-08 21:36:04",
                        context: "商品已经下单",
                        location: "",
                    },
                ];
            } else {
                this.$nofity.warning({
                    title: "警告",
                    message: "物流还没有发货",
                });
            }
        },
        // 修改订单信息
        editOrder(row) {
            this.editdialogShow = true;
        },
        // 修改订单提交
        editSubmit() {
            this.$refs.addressForm.validate((valid) => {
                if (!valid) return;
            });
        },
        // 页码修改
        pageChange(val) {
            this.form.pagenum = val;
            this.getOrderList();
        },
        reset() {
            this.form = {
                ...defaultOrder,
            };
            this.getOrderList();
        },
        async getOrderList() {
            let { data: res } = await this.$axios.get("orders", {
                params: this.form,
            });
            if (res.meta.status !== 200)
                return this.$message.error(res.meta.msg);
            this.total = res.data.total;
            this.orderList = res.data.goods;
        },
    },
    created() {
        this.getOrderList();
    },
};
</script>
<style>
</style>
